﻿<common:LayoutAwarePage
    x:Class="Netflix.ClientApp.View.TitlesPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:templateSelector="using:Netflix.ClientApp.TemplateSelector"
    xmlns:common="using:Netflix.ClientApp.Common" xmlns:converters="using:Netflix.ClientApp.Converters"
    x:Name="Root"
    DataContext="{Binding TitlesViewModel, Source={StaticResource Locator}}"
    mc:Ignorable="d">
    <common:LayoutAwarePage.Resources>
        <CollectionViewSource
                                x:Name="GroupedItemsViewSource"
                                Source="{Binding Groups}"
                                IsSourceGrouped="true"
                                ItemsPath="Items"
                                d:Source="{Binding Groups}"/>
       
        <templateSelector:NetFlixItemTemplateSelector x:Key="NetFlixItemTemplateSelector"/>
        <converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
        
        <converters:BooleanToVisibilityConverter x:Key="NagationBooleanToVisibilityConverter" IsNegation="True"/>
    </common:LayoutAwarePage.Resources>
    <Grid Background="#B9090B">
        <Grid  Name="LandscapeAndPortraitView" Visibility="Visible">
            <Grid.ChildrenTransitions>
                <TransitionCollection>
                    <EdgeUIThemeTransition />              
                </TransitionCollection>
            </Grid.ChildrenTransitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="140" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="120" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <!--Header -->
            <TextBlock x:Name="PageTitle"
                               Grid.Column="1"
                               IsHitTestVisible="false" Foreground="{StaticResource ForegroundBrush}"
                               Style="{StaticResource PageHeaderTextStyle}"
                               Text="My Netflix Catalog" />

            <!--Content -->
            <ProgressRing   Margin="0,0,120,0" Grid.Row="1" Grid.Column="1" IsActive="True" Foreground="White" Width="200" Height="200"
                            Visibility="{Binding IsToShowProgress,  Converter={StaticResource BooleanToVisibilityConverter}}" />
            <GridView  Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2"
                ItemClick="Title_OnItemClick"
                IsItemClickEnabled="True"
                SelectionMode="None" 
                Padding="116,0,40,46"
                Visibility="{Binding IsToShowProgress, Converter={StaticResource NagationBooleanToVisibilityConverter}}"
                ItemsSource="{Binding Source={StaticResource GroupedItemsViewSource}}"
                ItemTemplateSelector="{StaticResource NetFlixItemTemplateSelector}"
                ItemContainerStyle="{StaticResource GridViewItemStyle}">
                <GridView.ItemsPanel>
                        <ItemsPanelTemplate>
                            <VirtualizingStackPanel Orientation="Horizontal">
                                <VirtualizingStackPanel.ChildrenTransitions>
                                    <TransitionCollection>
                                        <EntranceThemeTransition />
                                        <RepositionThemeTransition />
                                    </TransitionCollection>
                                </VirtualizingStackPanel.ChildrenTransitions>
                            </VirtualizingStackPanel>
                        </ItemsPanelTemplate>
                    </GridView.ItemsPanel>
                <GridView.GroupStyle>
                    <GroupStyle>
                        <GroupStyle.HeaderTemplate>
                            <DataTemplate>
                                <Grid Margin="1,0,0,6">
                                    <Button
                                        AutomationProperties.Name="Group Title"
                                        Style="{StaticResource TextPrimaryButtonStyle}" >
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock Text="{Binding Label}"
                                                       Margin="3,-7,10,10"
                                                       Style="{StaticResource GroupHeaderTextStyle}" />
                                            <TextBlock Text="{StaticResource ChevronGlyph}" 
                                                       FontFamily="Segoe UI Symbol" 
                                                       Margin="0,-7,0,10" 
                                                       Style="{StaticResource GroupHeaderTextStyle}"/>
                                        </StackPanel>
                                    </Button>
                                </Grid>
                            </DataTemplate>
                        </GroupStyle.HeaderTemplate>
                        <GroupStyle.Panel>
                            <ItemsPanelTemplate>
                                <VariableSizedWrapGrid Orientation="Vertical" Margin="0,0,80,0"/>
                            </ItemsPanelTemplate>
                        </GroupStyle.Panel>
                    </GroupStyle>
                </GridView.GroupStyle>
            </GridView>
        </Grid>
        <Grid  Name="SnapView" Visibility="Collapsed">
            <TextBlock Text="My Netflix Catalog" HorizontalAlignment="Center" VerticalAlignment="Center" TextWrapping="Wrap"/>
        </Grid>
        <VisualStateManager.VisualStateGroups>
            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="SnapView"
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed" />
                        </ObjectAnimationUsingKeyFrames>

                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="LandscapeAndPortraitView"
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible" />
                        </ObjectAnimationUsingKeyFrames>


                    </Storyboard>
                </VisualState>
                <VisualState x:Name="Filled" >
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="SnapView"
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed" />
                        </ObjectAnimationUsingKeyFrames>

                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="LandscapeAndPortraitView"
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible" />
                        </ObjectAnimationUsingKeyFrames>


                    </Storyboard>
                </VisualState>
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="SnapView"
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed" />
                        </ObjectAnimationUsingKeyFrames>

                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="LandscapeAndPortraitView"
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible" />
                        </ObjectAnimationUsingKeyFrames>


                    </Storyboard>
                </VisualState>
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="SnapView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="LandscapeAndPortraitView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</common:LayoutAwarePage>